<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=0, viewport-fit=cover" />
	<title>eventLoop</title>
</head>
<body>
<script>
const result = [1, 2, 3, 4, 5].map(item => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			resolve(item)
		}, item * 1000)
	})
})

/*const result = [1, 2, 3, 4, 5].map(item => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			resolve(item)
		}, item === 3 ? 500 : item * 1000)
	})
})*/

/*const result = [1, 2, 3, 4, 5].map(item => {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			item === 3 ? reject(item * item) : resolve(item * item)
		}, item * 1000)
	})
})*/


Promise.race(result)
       .then(res => {
	       console.log(`res----`, res)
       })
       .catch(err => {
	       console.log(`err-----`, err)
       })
</script>
</body>
</html>
